package com.moniteach.server.db.bo;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.json.JSONObject;

import com.moniteach.utils.Resource;

@PersistenceCapable
public class Message {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String theme;

	@Persistent
	private String text;

	@Persistent
	private String type;

	@Persistent
	private Date dateCreate;

	@Persistent
	private Long sender;

	@Persistent
	private Long receiver;

	@Persistent
	private Boolean read;

	@Persistent
	private Date dateRead;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Date getDateCreate() {
		return dateCreate;
	}

	public void setDateCreate(Date dateCreate) {
		this.dateCreate = dateCreate;
	}

	public Long getSender() {
		return sender;
	}

	public void setSender(Long sender) {
		this.sender = sender;
	}

	public Long getReceiver() {
		return receiver;
	}

	public void setReceiver(Long receiver) {
		this.receiver = receiver;
	}

	public Boolean getRead() {
		return read;
	}

	public void setRead(Boolean read) {
		this.read = read;
	}

	public Date getDateRead() {
		return dateRead;
	}

	public void setDateRead(Date dateRead) {
		this.dateRead = dateRead;
	}

	public Message(String theme, String text, String type, Date dateCreate,
			Long sender, Long receiver, Boolean read, Date dateRead) {
		super();
		this.theme = theme;
		this.text = text;
		this.type = type;
		this.dateCreate = dateCreate;
		this.sender = sender;
		this.receiver = receiver;
		this.read = read;
		this.dateRead = dateRead;
	}

	public JSONObject toJSONObject() {
		JSONObject jo = new JSONObject();
		jo.put(Resource.Const.id, (id != null ? id : -1));
		jo.put(Resource.Const.theme, (theme != null ? theme : ""));
		jo.put(Resource.Const.text, (text != null ? text : ""));
		jo.put(Resource.Const.dateCreate, (dateCreate != null ? dateCreate : ""));
		jo.put(Resource.Const.read, read);
		jo.put(Resource.Const.type, type);
		jo.put(Resource.Const.sender, (sender != null ? sender : -1));
		jo.put(Resource.Const.receiver, (receiver != null ? receiver : -1));
		jo.put(Resource.Const.dateRead, (dateRead != null ? dateRead : ""));
		return jo;
	}

}
